package com.easy.user.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easy.common.bean.SysPermission;
import com.easy.common.service.IPermissionService;
import com.easy.user.mapper.PermissionMapper;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class PermissionService extends ServiceImpl<PermissionMapper,SysPermission> implements IPermissionService {
    @Override
    public SysPermission insert(SysPermission permission) {
        return null;
    }

    @Override
    public SysPermission update(SysPermission permission) {
        return null;
    }

    @Override
    public int delete(Integer id) {
        return 0;
    }

    @Override
    public SysPermission getByID(Integer id) {
        return null;
    }

    @Override
    public IPage<SysPermission> getListByPage(IPage page, SysPermission permission) {
        Wrapper wrapper=new QueryWrapper<SysPermission>(permission);
        return super.page(page,wrapper);
    }

    @Override
    public List<SysPermission> getList(SysPermission permission) {
        QueryWrapper<SysPermission> wrapper=new QueryWrapper<>();
        wrapper.eq("parentid",0);
        List<SysPermission> list=this.list(wrapper);
        for(SysPermission item:list){
            QueryWrapper<SysPermission> itemwrapper=new QueryWrapper<>();
            itemwrapper.eq("parentid",item.getId());
            item.setChildren(list(itemwrapper));
        }
        return list;
    }
}
